package com.gragra.distances.tests;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import com.gragra.distances.CosineMeanFactory;
import com.gragra.distances.CosineSimilarity;
import com.gragra.sampling.vector.VectorStructure;
public class TestCosineSimilarity
{
	/**
	 * 
	 */
	private final CosineMeanFactory fact = new CosineMeanFactory();
	/**
	 * 
	 */
	private CosineSimilarity cs;
	@Before
	public void setUp() throws Exception
	{cs = (CosineSimilarity) fact.createInstance();}
	@Test
	public void testAdd()
	{
		assertTrue(cs.empty());
		cs.add(new VectorStructure(3, new double[] {2,4,5}, new int[][] {{2,1},{2,2},{3,4}},2));
		assertFalse(cs.empty());
		cs.add(new VectorStructure(3, new double[] {5,7,9}, new int[][] {{2,1},{2,2},{3,4}},2));
		assertFalse(cs.empty());
	}
	@Test
	public void testGetDistance()
	{
		assertTrue(cs.empty());
		cs.add(new VectorStructure(3, new double[] {2,4,5}, new int[][] {{2,1},{2,2},{3,4}},2));
		assertFalse(cs.empty());
		cs.add(new VectorStructure(3, new double[] {5,7,9}, new int[][] {{2,1},{2,2},{3,4}},2));
		assertFalse(cs.empty());
		cs.set();
		assertEquals(0.4389208732384178,cs.getDistance(new VectorStructure(3, new double[] {2,4,3}, new int[][] {{2,1},{2,2},{3,5}},2)),0.0000000001);
	}
}